﻿using System;
using FU.Capstones.IMS.Web.Common;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.DataContracts;
using FU.Capstones.IMS.Web.Common.InventoryServiceProxy.EventArgs;

namespace FU.Capstones.IMS.Web.Silverlight.Models
{
    public class WarehouseDetailModel : ModelBase
    {
        public WarehouseDetailModel()
        {
            client.GetSingleWarehouseCompleted += DoGetSingleWarehouseCompleted;
            client.InsertWarehouseCompleted += DoInsertWarehouseCompleted;
            client.UpdateWarehouseCompleted += DoUpdateWarehouseCompleted;
            client.GetAuthorizationCollectionCompleted += DoGetAuthorizationCollectionCompleted;
            client.GetEmployeeCollectionCompleted += DoGetEmployeeCollectionCompleted;
        }

        #region GetAuthorizationCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Authorization>> GetAuthorizationCollectionCompleted;

        public int GetAuthorizationCollectionAsync()
        {
            client.GetAuthorizationCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        private void DoGetAuthorizationCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Authorization> e)
        {
            if (GetAuthorizationCollectionCompleted != null)
            {
                GetAuthorizationCollectionCompleted(sender, e);
            }
        }

        #endregion

        #region UpdateWarehouse

        public event EventHandler<FeedbackCompletedEventArgs> UpdateWarehouseCompleted;

        public int UpdateWarehouseAsync(Warehouse data)
        {
            client.UpdateWarehouseAsync(data);
            return WebConstants.MagicNumer;
        }

        void DoUpdateWarehouseCompleted(object sender, FeedbackCompletedEventArgs e)
        {
            if (UpdateWarehouseCompleted != null)
            {
                UpdateWarehouseCompleted(sender, e);
            }
        }

        #endregion

        #region InsertWarehouse

        public event EventHandler<SingleFeedbackCompletedEventArgs<int>> InsertWarehouseCompleted;

        public int InsertWarehouseAsync(Warehouse warehouse)
        {
            client.InsertWarehouseAsync(warehouse);
            return WebConstants.MagicNumer;
        }

        void DoInsertWarehouseCompleted(object sender, SingleFeedbackCompletedEventArgs<int> e)
        {
            if (InsertWarehouseCompleted != null)
            {
                InsertWarehouseCompleted(sender, e);
            }
        }

        #endregion

        #region GetSingleWarehouse

        public event EventHandler<SingleFeedbackCompletedEventArgs<Warehouse>> GetSingleWarehouseCompleted;

        public int GetSingleWarehouseAsync(int warehouseId)
        {
            client.GetSingleWarehouseAsync(warehouseId);
            return WebConstants.MagicNumer;
        }

        void DoGetSingleWarehouseCompleted(object sender, SingleFeedbackCompletedEventArgs<Warehouse> e)
        {
            if (GetSingleWarehouseCompleted != null)
            {
                GetSingleWarehouseCompleted(sender, e);
            }
        }

        #endregion

        #region GetRoleCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Employee>> GetEmployeeCollectionCompleted;

        public int GetEmployeeCollectionAsync()
        {
            client.GetEmployeeCollectionAsync(false);
            return WebConstants.MagicNumer;
        }

        void DoGetEmployeeCollectionCompleted(object sender, CollectionFeedbackCompletedEventArgs<Employee> e)
        {
            if (GetEmployeeCollectionCompleted != null)
            {
                GetEmployeeCollectionCompleted(sender, e);
            }
        }

        #endregion
    }
}
